package com.xtianzhuang.www.service.impl;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xtianzhuang.www.dao.TdPInterfaceMapper;
import com.xtianzhuang.www.dao.TdPParamMapper;
import com.xtianzhuang.www.dao.TdPProjectMapper;
import com.xtianzhuang.www.dao.TdPProjectParamMapper;
import com.xtianzhuang.www.dao.TdPTaskMapper;
import com.xtianzhuang.www.dao.TdPTaskSelfMapper;
import com.xtianzhuang.www.dao.TmPInterfaceParamMapper;
import com.xtianzhuang.www.dao.TmPProjectIntfMapper;
import com.xtianzhuang.www.dao.TmPProjectTaskMapper;
import com.xtianzhuang.www.dao.VInterfaceParamMapper;
import com.xtianzhuang.www.dao.VProjectIntfMapper;
import com.xtianzhuang.www.dao.VProjectTaskMapper;
import com.xtianzhuang.www.entity.TdPInterface;
import com.xtianzhuang.www.entity.TdPParam;
import com.xtianzhuang.www.entity.TdPProject;
import com.xtianzhuang.www.entity.TdPProjectExample;
import com.xtianzhuang.www.entity.TdPProjectParam;
import com.xtianzhuang.www.entity.TdPProjectParamExample;
import com.xtianzhuang.www.entity.TdPTask;
import com.xtianzhuang.www.entity.TmPInterfaceParam;
import com.xtianzhuang.www.entity.TmPInterfaceParamExample;
import com.xtianzhuang.www.entity.TmPProjectIntf;
import com.xtianzhuang.www.entity.TmPProjectIntfExample;
import com.xtianzhuang.www.entity.TmPProjectTask;
import com.xtianzhuang.www.entity.TmPProjectTaskExample;
import com.xtianzhuang.www.entity.VInterfaceParam;
import com.xtianzhuang.www.entity.VInterfaceParamExample;
import com.xtianzhuang.www.entity.VProjectIntf;
import com.xtianzhuang.www.entity.VProjectIntfExample;
import com.xtianzhuang.www.entity.VProjectTask;
import com.xtianzhuang.www.entity.VProjectTaskExample;
import com.xtianzhuang.www.entity.constants.CodeConstants;
import com.xtianzhuang.www.entity.constants.IsDeletedConstants;
import com.xtianzhuang.www.entity.constants.ParamDataTypeConstants;
import com.xtianzhuang.www.entity.constants.ParamDirectionConstants;
import com.xtianzhuang.www.entity.constants.ParamTypeConstants;
import com.xtianzhuang.www.entity.request.AddTaskRequest;
import com.xtianzhuang.www.entity.request.DeleteInterfaceParamsRequest;
import com.xtianzhuang.www.entity.request.DeleteProjectInterfaceRequest;
import com.xtianzhuang.www.entity.request.DeleteProjectParamRequest;
import com.xtianzhuang.www.entity.request.DeleteTaskRequest;
import com.xtianzhuang.www.entity.request.SaveInterfaceParamRequest;
import com.xtianzhuang.www.entity.request.SaveProjectInterfaceRequest;
import com.xtianzhuang.www.entity.request.SaveProjectParamRequest;
import com.xtianzhuang.www.entity.request.UpdateTaskRequest;
import com.xtianzhuang.www.entity.response.AddTaskResponse;
import com.xtianzhuang.www.entity.response.UpdateTaskResponse;
import com.xtianzhuang.www.service.ProjectService;
import com.xtianzhuang.www.utils.PageData;
import com.xtianzhuang.www.utils.StringUtil;

@Service("projectServiceBiz")
@Transactional(rollbackFor = Exception.class)
public class ProjectServiceBiz extends CommonServiceBiz implements ProjectService {
	@Autowired
	private TdPProjectMapper tdPProjectMapper;
	@Autowired
	private TdPProjectParamMapper tdPProjectParamMapper;
	@Autowired
	private TdPInterfaceMapper tdPInterfaceMapper;
	@Autowired
	private TdPParamMapper tdPParamMapper;
	@Autowired
	private TmPProjectIntfMapper tmPProjectIntfMapper;
	@Autowired
	private TmPInterfaceParamMapper tmPInterfaceParamMapper;
	@Autowired
	private TdPTaskSelfMapper tdPTaskSelfMapper;
	@Autowired
	private TdPTaskMapper tdPTaskMapper;
	@Autowired
	TmPProjectTaskMapper tmPProjectTaskMapper;
	@Autowired
	private VProjectIntfMapper vProjectIntfMapper;
	@Autowired
	private VInterfaceParamMapper vInterfaceParamMapper;
	@Autowired
	private VProjectTaskMapper vProjectTaskMapper;

	@Override
	public long projetListCountQuery(TdPProjectExample example) {
		// TODO Auto-generated method stub
		return tdPProjectMapper.countByExample(example);
	}

	@Override
	public List<TdPProject> projetListQuery(TdPProjectExample example) {
		// TODO Auto-generated method stub
		return tdPProjectMapper.selectByExample(example);
	}

	@Override
	public long projetParamListCountQuery(TdPProjectParamExample example) {
		// TODO Auto-generated method stub
		return tdPProjectParamMapper.countByExample(example);
	}

	@Override
	public List<TdPProjectParam> projetParamListQuery(TdPProjectParamExample example) {
		// TODO Auto-generated method stub
		return tdPProjectParamMapper.selectByExample(example);
	}

	@Override
	public List<VProjectIntf> projetDetailQuery(VProjectIntfExample example) {
		// TODO Auto-generated method stub
		return vProjectIntfMapper.selectByExample(example);
	}

	@Override
	public long projetDetailCountQuery(VProjectIntfExample example) {
		// TODO Auto-generated method stub
		return vProjectIntfMapper.countByExample(example);
	}

	@Override
	public List<TdPProject> getProjectList() {
		// TODO Auto-generated method stub
		TdPProjectExample example = new TdPProjectExample();
		example.or().andProjectStateEqualTo("01");
		return tdPProjectMapper.selectByExample(example);
	}

	@Override
	public AddTaskResponse addTask(AddTaskRequest request) {
		AddTaskResponse response = new AddTaskResponse();
		// TODO Auto-generated method stub
		TdPProject tdPProject = tdPProjectMapper.selectByPrimaryKey(request.getProjectId());
		if (tdPProject == null) {
			response.setCode(CodeConstants.FAIL);
			response.setMessage("未找到该项目");
		} else {
			String projectName = tdPProject.getProjectName();
			String max = tdPTaskSelfMapper.selectMaxTaskNum(projectName + "%", projectName.length() + 2);
			String taskId = "";
			if (!StringUtils.isEmpty(max)) {
				taskId = projectName + "-" + (Integer.valueOf(max) + 1);
			} else {
				taskId = projectName + "-" + "1";
			}
			// 添加任务
			addTdPTask(taskId, request.getTaskName(), request.getUserId(), "00", request.getTime(),
					request.getTaskType(), request.getDescription());
			// 添加关系表
			addTdPProjectTask(taskId, tdPProject.getProjectId());
			response.setCode(CodeConstants.SUCCESS);
			response.setMessage("新建成功，任务编号为" + taskId);
		}
		return response;
	}

	public int addTdPTask(String taskId, String taskName, int taskUserId, String state, int time, String taskType,
			String description) {
		TdPTask tdPTask = new TdPTask();
		tdPTask.setTaskName(taskName);
		tdPTask.setTaskId(taskId);
		tdPTask.setCreateStaffId("zxt");
		tdPTask.setCreateTime(new Date());
		tdPTask.setTaskUserId(taskUserId);
		tdPTask.setTaskType(taskType);
		tdPTask.setDescription(description);
		tdPTask.setState(state);
		tdPTask.setTime(time);
		return tdPTaskMapper.insert(tdPTask);
	}

	public int addTdPProjectTask(String taskId, int projectId) {
		TmPProjectTask tmPProjectTask = new TmPProjectTask();
		tmPProjectTask.setTaskId(taskId);
		tmPProjectTask.setProjectId(projectId);
		tmPProjectTask.setIsDeleted(IsDeletedConstants.IN_USE);
		tmPProjectTask.setCreateTime(new Date());
		tmPProjectTask.setCreateStaffId(subject.getPrincipal().getUserName());
		return tmPProjectTaskMapper.insert(tmPProjectTask);
	}

	@Override
	public List<VProjectTask> projetTaskQuery(VProjectTaskExample example) {
		// TODO Auto-generated method stub
		return vProjectTaskMapper.selectByExample(example);
	}

	@Override
	public long projetTaskCountQuery(VProjectTaskExample example) {
		// TODO Auto-generated method stub
		return vProjectTaskMapper.countByExample(example);
	}

	@Override
	public List<TdPProject> selectProjectInUse() {
		// TODO Auto-generated method stub
		TdPProjectExample example = new TdPProjectExample();
		return tdPProjectMapper.selectByExample(example);
	}

	@Override
	public UpdateTaskResponse updateTask(UpdateTaskRequest request) {
		UpdateTaskResponse response = new UpdateTaskResponse();
		// TODO Auto-generated method stub
		TdPTask tdPTask = new TdPTask();
		tdPTask = tdPTaskMapper.selectByPrimaryKey(request.getTaskId());
		if (tdPTask != null) {
			tdPTask.setUpdateTime(new Date());
			tdPTask.setUpdateStaffId(subject.getPrincipal().getUserName());
			tdPTask.setState(request.getState());
			tdPTask.setTaskName(request.getTaskName());
			tdPTask.setDescription(request.getDescription());
			tdPTask.setTime(request.getTime());
			int count = tdPTaskMapper.updateByPrimaryKey(tdPTask);
			if (count > 0) {
				response.setCode(CodeConstants.SUCCESS);
				response.setMessage("更新成功");
			} else {
				response.setCode(CodeConstants.FAIL);
				response.setMessage("更新失败");
			}
		} else {
			response.setCode(CodeConstants.FAIL);
			response.setMessage("更新失败:未找到改任务");
		}
		return response;
	}

	@Override
	public void deleteProjectTask(DeleteTaskRequest request) {
		// TODO Auto-generated method stub
		TmPProjectTaskExample example = new TmPProjectTaskExample();
		example.or().andProjectIdEqualTo(request.getProjectId()).andTaskIdEqualTo(request.getTaskId());
		TmPProjectTask record = new TmPProjectTask();
		record.setUpdateStaffId(subject.getPrincipal().getUserName());
		record.setUpdateTime(new Date());
		record.setIsDeleted(IsDeletedConstants.DELETED);
		tmPProjectTaskMapper.updateByExampleSelective(record, example);
	}

	@Override
	public void addProjectInterface(SaveProjectInterfaceRequest request) throws Exception {
		// TODO Auto-generated method stub
		if (checkaddInterfaceRequest(request)) {
			Integer interfaceId = addTdPInterface(request);
			addTmPProjectIntf(request, interfaceId);
		}

	}

	@Override
	public void updateProjectInterface(SaveProjectInterfaceRequest request) throws Exception {
		// TODO Auto-generated method stub
		if (checkaddInterfaceRequest(request)) {
			updateTdPInterface(request);
		}

	}

	public boolean checkaddInterfaceRequest(SaveProjectInterfaceRequest request) throws Exception {
		if (StringUtils.isEmpty(request.getInterfaceCode())) {
			throw new Exception("请输入接口编码！");
		}
		if (StringUtils.isEmpty(request.getInterfaceName())) {
			throw new Exception("请输入接口名称！");
		}
		if (request.getInterfaceId() == null) {
			VProjectIntfExample example = new VProjectIntfExample();
			example.or().andProjectIdEqualTo(request.getProjectId()).andInterfaceCodeEqualTo(request.getInterfaceCode())
					.andIsDeletedEqualTo(IsDeletedConstants.IN_USE);
			long count = vProjectIntfMapper.countByExample(example);
			if (count > 0) {
				throw new Exception("接口编码不能重复！");
			}
		}

		return true;
	}

	public Integer addTdPInterface(SaveProjectInterfaceRequest request) {
		// TODO Auto-generated method stub
		TdPInterface tdPInterface = new TdPInterface();

		tdPInterface.setInterfaceType(request.getInterfaceType());
		tdPInterface.setInterfaceName(request.getInterfaceName());
		tdPInterface.setInterfaceCode(request.getInterfaceCode());
		tdPInterface.setState("1");
		tdPInterface.setDescription(request.getDescription());
		tdPInterface.setInputInterfaceName(request.getInputInterfaceName());
		tdPInterface.setOutputInterfaceName(request.getOutputInterfaceName());
		tdPInterface.setShowOrder(request.getShowOrder());
		tdPInterface.setCreateStaffId(subject.getPrincipal().getUserName());
		tdPInterface.setInterfacePath(request.getInterfacePath());
		tdPInterface.setCreateTime(new Date());
		tdPInterfaceMapper.insert(tdPInterface);
		return tdPInterface.getInterfaceId();
	}

	public void updateTdPInterface(SaveProjectInterfaceRequest request) {
		// TODO Auto-generated method stub
		TdPInterface tdPInterface = new TdPInterface();

		tdPInterface.setInterfaceId(request.getInterfaceId());
		tdPInterface.setInterfaceName(request.getInterfaceName());
		tdPInterface.setInterfaceCode(request.getInterfaceCode());
		tdPInterface.setState("1");
		tdPInterface.setInterfacePath(request.getInterfacePath());
		tdPInterface.setInterfaceType(request.getInterfaceType());
		tdPInterface.setDescription(request.getDescription());
		tdPInterface.setInputInterfaceName(request.getInputInterfaceName());
		tdPInterface.setOutputInterfaceName(request.getOutputInterfaceName());
		tdPInterface.setShowOrder(request.getShowOrder());
		tdPInterface.setUpdateStaffId(subject.getPrincipal().getUserName());
		tdPInterface.setUpdateTime(new Date());
		tdPInterfaceMapper.updateByPrimaryKeySelective(tdPInterface);
	}

	public void addTmPProjectIntf(SaveProjectInterfaceRequest request, Integer interfaceId) {
		// TODO Auto-generated method stub
		TmPProjectIntf tmPProjectIntf = new TmPProjectIntf();
		tmPProjectIntf.setProjectId(request.getProjectId());
		tmPProjectIntf.setInterfaceId(interfaceId);
		tmPProjectIntf.setIsDeleted(IsDeletedConstants.IN_USE);
		tmPProjectIntf.setCreateStaffId(subject.getPrincipal().getUserName());
		tmPProjectIntf.setCreateTime(new Date());
		tmPProjectIntfMapper.insert(tmPProjectIntf);
	}

	@Override
	public long interfaceParamsCountQuery(VInterfaceParamExample example) {
		// TODO Auto-generated method stub
		return vInterfaceParamMapper.countByExample(example);
	}

	@Override
	public List<VInterfaceParam> interfaceParamsQuery(VInterfaceParamExample example) {
		// TODO Auto-generated method stub
		return vInterfaceParamMapper.selectByExample(example);
	}

	@Override
	public void addInterfaceParam(SaveInterfaceParamRequest request) throws Exception {
		// TODO Auto-generated method stub
		if (checkaddParamsRequest(request)) {
			Integer paramId = addTdPParam(request);
			addTmPInterfaceParam(request, paramId);
		}
	}

	@Override
	public void updateInterfaceParam(SaveInterfaceParamRequest request) throws Exception {
		// TODO Auto-generated method stub
		if (checkaddParamsRequest(request)) {
			updateTdPParam(request);
		}
	}

	@Override
	public void addProjectParam(SaveProjectParamRequest request) throws Exception {
		// TODO Auto-generated method stub
		TdPProjectParam tdPProjectParam = new TdPProjectParam();
		tdPProjectParam.setCreateStaffId(subject.getPrincipal().getUserName());
		tdPProjectParam.setCreateTime(new Date());
		tdPProjectParam.setProjectId(request.getProjectId());
		tdPProjectParam.setParamCode(request.getParamCode());
		tdPProjectParam.setParamName(request.getParamName());
		tdPProjectParam.setParamVal(request.getParamVal());
		tdPProjectParam.setDescription(request.getDescription());
		tdPProjectParam.setIsDeleted(IsDeletedConstants.IN_USE);
		tdPProjectParam.setParentParamId(request.getParentParamId());
		tdPProjectParamMapper.insert(tdPProjectParam);
	}

	@Override
	public void updateProjectParam(SaveProjectParamRequest request) throws Exception {
		// TODO Auto-generated method stub
		TdPProjectParam tdPProjectParam = new TdPProjectParam();
		tdPProjectParam.setUpdateStaffId(subject.getPrincipal().getUserName());
		tdPProjectParam.setUpdateTime(new Date());
		tdPProjectParam.setProjectId(request.getProjectId());
		tdPProjectParam.setParamCode(request.getParamCode());
		tdPProjectParam.setParamName(request.getParamName());
		tdPProjectParam.setParamVal(request.getParamVal());
		tdPProjectParam.setDescription(request.getDescription());
		tdPProjectParam.setParentParamId(request.getParentParamId());
		tdPProjectParam.setId(request.getId());
		tdPProjectParamMapper.updateByPrimaryKey(tdPProjectParam);
	}


	public boolean checkaddParamsRequest(SaveInterfaceParamRequest request) throws Exception {
		if (StringUtils.isEmpty(request.getParamCode())) {
			throw new Exception("请输入参数编码！");
		}
		if (StringUtils.isEmpty(request.getParamName())) {
			throw new Exception("请输入参数名称！");
		}
		if (request.getParamId() == null) {
			VInterfaceParamExample example = new VInterfaceParamExample();
			if (request.getParentParamId() != null) {
				example.or().andInterfaceIdEqualTo(request.getInterfaceId())
						.andIsDeletedEqualTo(IsDeletedConstants.IN_USE).andParamCodeEqualTo(request.getParamCode())
						.andParamDirectionEqualTo(request.getParamDirection())
						.andParentParamIdEqualTo(request.getParentParamId());
			} else {
				example.or().andInterfaceIdEqualTo(request.getInterfaceId())
						.andIsDeletedEqualTo(IsDeletedConstants.IN_USE).andParamCodeEqualTo(request.getParamCode())
						.andParamDirectionEqualTo(request.getParamDirection());
			}

			long count = vInterfaceParamMapper.countByExample(example);
			if (count > 0) {
				throw new Exception("参数编码不能重复！");
			}
		}
		return true;
	}

	public Integer addTdPParam(SaveInterfaceParamRequest request) {
		// TODO Auto-generated method stub
		TdPParam tdPParam = new TdPParam();
		tdPParam.setCreateStaffId(subject.getPrincipal().getUserName());
		tdPParam.setCreateTime(new Date());
		tdPParam.setParamDataLength(request.getParamDataLength());
		tdPParam.setParamDataType(request.getParamDataType());
		tdPParam.setDescription(request.getDescription());
		tdPParam.setIsNotNull(request.getIsNotNull());
		tdPParam.setParamCode(request.getParamCode());
		tdPParam.setParamName(request.getParamName());
		tdPParam.setParamState("1");
		tdPParam.setParentParamId(request.getParentParamId());
		tdPParam.setParamDirection(request.getParamDirection());
		tdPParam.setParamType(request.getParamType());
		tdPParam.setDefaultValue(request.getDefaultValue());
		tdPParam.setParamOrder(request.getParamOrder());
		tdPParamMapper.insert(tdPParam);
		return tdPParam.getParamId();
	}

	public void updateTdPParam(SaveInterfaceParamRequest request) {
		// TODO Auto-generated method stub
		TdPParam tdPParam = new TdPParam();
		tdPParam.setUpdateStaffId(subject.getPrincipal().getUserName());
		tdPParam.setUpdateTime(new Date());
		tdPParam.setParamId(request.getParamId());
		tdPParam.setParamDataLength(request.getParamDataLength());
		tdPParam.setParamDataType(request.getParamDataType());
		tdPParam.setDescription(request.getDescription());
		tdPParam.setIsNotNull(request.getIsNotNull());
		tdPParam.setParamCode(request.getParamCode());
		tdPParam.setParamName(request.getParamName());
		tdPParam.setParamState("1");
		tdPParam.setParentParamId(request.getParentParamId());
		tdPParam.setParamDirection(request.getParamDirection());
		tdPParam.setParamType(request.getParamType());
		tdPParam.setDefaultValue(request.getDefaultValue());
		tdPParam.setParamOrder(request.getParamOrder());
		tdPParamMapper.updateByPrimaryKeySelective(tdPParam);
	}

	public void addTmPInterfaceParam(SaveInterfaceParamRequest request, Integer paramId) {
		// TODO Auto-generated method stub
		TmPInterfaceParam tmPInterfaceParam = new TmPInterfaceParam();
		tmPInterfaceParam.setInterfaceId(request.getInterfaceId());
		tmPInterfaceParam.setParamId(paramId);
		tmPInterfaceParam.setIsDeleted(IsDeletedConstants.IN_USE);
		tmPInterfaceParam.setCreateStaffId(subject.getPrincipal().getUserName());
		tmPInterfaceParam.setCreateTime(new Date());
		tmPInterfaceParamMapper.insert(tmPInterfaceParam);
	}


	@Override
	public void deleteInterfaceParams(DeleteInterfaceParamsRequest request) {
		// TODO Auto-generated method stub

		// 如果有子节点 递归删除子节点
		deleteInterfaceParamsChild(request.getInterfaceId(), request.getParamId());
		TmPInterfaceParamExample example = new TmPInterfaceParamExample();
		example.or().andParamIdEqualTo(request.getParamId()).andInterfaceIdEqualTo(request.getInterfaceId());
		TmPInterfaceParam tmPInterfaceParam = new TmPInterfaceParam();
		tmPInterfaceParam.setIsDeleted(IsDeletedConstants.DELETED);
		tmPInterfaceParam.setUpdateStaffId(subject.getPrincipal().getUserName());
		tmPInterfaceParam.setUpdateTime(new Date());
		tmPInterfaceParamMapper.updateByExampleSelective(tmPInterfaceParam, example);

	}

	/**
	 * 如果有parantParamId =该paramId 的 也同时失效
	 */
	public void deleteInterfaceParamsChild(Integer interfaceId, Integer paramId) {
		// TODO Auto-generated method stub
		VInterfaceParamExample example = new VInterfaceParamExample();
		example.or().andParentParamIdEqualTo(paramId);
		List<VInterfaceParam> list = vInterfaceParamMapper.selectByExample(example);
		if (list != null && list.size() > 0) {
			for (VInterfaceParam item : list) {
				deleteInterfaceParamsChild(interfaceId, item.getParamId());
				TmPInterfaceParamExample tmPInterfaceParamExample = new TmPInterfaceParamExample();
				tmPInterfaceParamExample.or().andParamIdEqualTo(item.getParamId()).andInterfaceIdEqualTo(interfaceId);
				TmPInterfaceParam tmPInterfaceParam = new TmPInterfaceParam();
				tmPInterfaceParam.setIsDeleted(IsDeletedConstants.DELETED);
				tmPInterfaceParam.setUpdateStaffId(subject.getPrincipal().getUserName());
				tmPInterfaceParam.setUpdateTime(new Date());
				tmPInterfaceParamMapper.updateByExampleSelective(tmPInterfaceParam, tmPInterfaceParamExample);
			}

		}
	}

	@Override
	public void deleteProjectParam(DeleteProjectParamRequest request) {
		// TODO Auto-generated method stub
		tdPProjectParamMapper.deleteByPrimaryKey(request.getId());
	}

	@Override
	public void deleteProjectInterface(DeleteProjectInterfaceRequest request) {
		// TODO Auto-generated method stub
		TmPProjectIntfExample example = new TmPProjectIntfExample();
		example.or().andProjectIdEqualTo(request.getProjectId()).andInterfaceIdEqualTo(request.getInterfaceId());
		TmPProjectIntf tmPProjectIntf = new TmPProjectIntf();
		tmPProjectIntf.setIsDeleted(IsDeletedConstants.DELETED);
		tmPProjectIntf.setUpdateStaffId(subject.getPrincipal().getUserName());
		tmPProjectIntf.setUpdateTime(new Date());
		tmPProjectIntfMapper.updateByExampleSelective(tmPProjectIntf, example);
	}

	@Override
	public String getInput(Integer interfaceId) {
		// TODO Auto-generated method stub
		VInterfaceParamExample example = new VInterfaceParamExample();
		example.or().andInterfaceIdEqualTo(interfaceId).andParentParamIdIsNull()
				.andParamDirectionEqualTo(ParamDirectionConstants.INPUT);
		List<VInterfaceParam> list = vInterfaceParamMapper.selectByExample(example);
		JSONObject jsonObject = new JSONObject();
		JSONObject reqBody = getInputString(new JSONObject(), list, interfaceId);
		String reqBodyName = getReqBodyName();
		jsonObject.put(reqBodyName, reqBody);
		TdPProjectParam reqHeadPram = getReqHead();
		jsonObject = getReqHeadChild(jsonObject, reqHeadPram);
		return jsonObject.toJSONString();
	}

	public TdPProjectParam getReqHead() {
		TdPProjectParamExample example = new TdPProjectParamExample();
		example.or().andIsDeletedEqualTo(IsDeletedConstants.IN_USE).andParamCodeEqualTo("reqHead");
		List<TdPProjectParam> list = tdPProjectParamMapper.selectByExample(example);
		if (list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	public JSONObject getReqHeadChild(JSONObject jsonObject, TdPProjectParam tdPProjectParam) {
		if (tdPProjectParam != null) {
			TdPProjectParamExample example = new TdPProjectParamExample();
			example.or().andIsDeletedEqualTo(IsDeletedConstants.IN_USE)
					.andParentParamIdEqualTo(tdPProjectParam.getId());
			List<TdPProjectParam> list = tdPProjectParamMapper.selectByExample(example);
			JSONObject reqHead = new JSONObject();
			if (list.size() > 0) {
				for (TdPProjectParam item : list) {
					reqHead.put(item.getParamCode(), item.getParamVal());
				}
			}
			jsonObject.put(tdPProjectParam.getParamVal(), reqHead);
		} else {
			JSONObject reqHead = new JSONObject();

			jsonObject.put("reqHead", reqHead);
		}

		return jsonObject;
	}

	public String getReqBodyName() {
		TdPProjectParamExample example = new TdPProjectParamExample();
		example.or().andIsDeletedEqualTo(IsDeletedConstants.IN_USE).andParamCodeEqualTo("reqBody");
		List<TdPProjectParam> list = tdPProjectParamMapper.selectByExample(example);
		if (list.size() > 0) {
			return list.get(0).getParamVal();
		}
		return "reqBody";
	}

	public JSONObject getInputString(JSONObject input, List<VInterfaceParam> list, Integer interfaceId) {
		for (VInterfaceParam item : list) {
			if (item.getParamType().equals(ParamTypeConstants.COMMON)) {
				if (item.getParamDataType().equals(ParamDataTypeConstants.IS_STRING)) {
					input.put(item.getParamCode(), item.getDefaultValue());
				} else if (item.getParamDataType().equals(ParamDataTypeConstants.IS_INTEGER)) {
					if (StringUtils.isNotEmpty(item.getDefaultValue())) {
						input.put(item.getParamCode(), Integer.valueOf(item.getDefaultValue()));
					} else {
						input.put(item.getParamCode(), 0);
					}

				} else if (item.getParamDataType().equals(ParamDataTypeConstants.IS_LONG)) {
					if (StringUtils.isNotEmpty(item.getDefaultValue())) {
						input.put(item.getParamCode(), Long.valueOf(item.getDefaultValue()));
					} else {
						input.put(item.getParamCode(), 0);
					}

				}else if (item.getParamDataType().equals(ParamDataTypeConstants.IS_BIG_DECIMAL)) {
					if (StringUtils.isNotEmpty(item.getDefaultValue())) {
						input.put(item.getParamCode(), new BigDecimal(item.getDefaultValue()));
					} else {
						input.put(item.getParamCode(), 0);
					}
				} else {
					input.put(item.getParamCode(), item.getDefaultValue());
				}

			} else if (item.getParamType().equals(ParamTypeConstants.OBJECT)) {
				JSONObject object = new JSONObject();
				input.put(item.getParamCode(), new JSONObject());
				VInterfaceParamExample example = new VInterfaceParamExample();
				example.or().andInterfaceIdEqualTo(interfaceId).andParentParamIdEqualTo(item.getParamId())
						.andParamDirectionEqualTo(ParamDirectionConstants.INPUT);
				List<VInterfaceParam> list2 = vInterfaceParamMapper.selectByExample(example);
				getInputString(object, list2, interfaceId);
				input.put(item.getParamCode(), object);
			} else if (item.getParamType().equals(ParamTypeConstants.LIST)) {// 列表 只展示一条示例
				JSONArray jsonArray = new JSONArray();
				JSONObject object = new JSONObject();
				input.put(item.getParamCode(), new JSONObject());
				VInterfaceParamExample example = new VInterfaceParamExample();
				example.or().andInterfaceIdEqualTo(interfaceId).andParentParamIdEqualTo(item.getParamId())
						.andParamDirectionEqualTo(ParamDirectionConstants.INPUT);
				List<VInterfaceParam> list2 = vInterfaceParamMapper.selectByExample(example);
				getInputString(object, list2, interfaceId);
				jsonArray.add(object);
				input.put(item.getParamCode(), jsonArray);
			}
		}
		return input;
	}

	@Override
	public JSONArray getParamTree(Integer interfaceId) {
		// TODO Auto-generated method stub
		JSONArray array = new JSONArray();
		VInterfaceParamExample example = new VInterfaceParamExample();
		example.or().andInterfaceIdEqualTo(interfaceId).andParentParamIdIsNull()
				.andParamDirectionEqualTo(ParamDirectionConstants.INPUT);
		List<VInterfaceParam> list = vInterfaceParamMapper.selectByExample(example);
		JSONObject jsonObject1 = new JSONObject();
		JSONObject reqBody = new JSONObject();
		JSONArray reqBodyArray = getInputParamTree(new JSONArray(), list, interfaceId, ParamDirectionConstants.INPUT);
		reqBody.put("id", "reqBody");
		reqBody.put("title", "请求体");
		reqBody.put("children", reqBodyArray);
		TdPProjectParam reqHeadPram = getReqHead();
		JSONObject reqHead = getReqHeadChild(reqHeadPram);
		JSONArray jsonArray = new JSONArray();
		jsonArray.add(reqHead);
		jsonArray.add(reqBody);
		jsonObject1.put("id", "input");
		jsonObject1.put("title", "入参");
		jsonObject1.put("children", jsonArray);
		VInterfaceParamExample example2 = new VInterfaceParamExample();
		example2.or().andInterfaceIdEqualTo(interfaceId).andParentParamIdIsNull()
				.andParamDirectionEqualTo(ParamDirectionConstants.OUTPUT);
		List<VInterfaceParam> list2 = vInterfaceParamMapper.selectByExample(example2);
		JSONObject rspBody = new JSONObject();
		JSONArray rspBodyArray = getInputParamTree(new JSONArray(), list2, interfaceId, ParamDirectionConstants.OUTPUT);
		rspBody.put("id", "rspBody");
		rspBody.put("title", "响应体");
		rspBody.put("children", rspBodyArray);
		JSONArray jsonArray2 = new JSONArray();
		jsonArray2.add(rspBody);
		JSONObject jsonObject2 = new JSONObject();
		jsonObject2.put("id", "output");
		jsonObject2.put("title", "出参");
		jsonObject2.put("children", jsonArray2);
		array.add(jsonObject1);
		array.add(jsonObject2);
		logger.info("\n" + JSONObject.toJSONString(array));
		return array;
	}

	public JSONObject getReqHeadChild(TdPProjectParam tdPProjectParam) {
		JSONObject jsonObject = new JSONObject();
		if (tdPProjectParam != null) {
			jsonObject.put("id", tdPProjectParam.getParamCode());
			jsonObject.put("title", tdPProjectParam.getParamName());
			TdPProjectParamExample example = new TdPProjectParamExample();
			example.or().andIsDeletedEqualTo(IsDeletedConstants.IN_USE)
					.andParentParamIdEqualTo(tdPProjectParam.getId());
			List<TdPProjectParam> list = tdPProjectParamMapper.selectByExample(example);
			if (list.size() > 0) {
				JSONArray jsonArray = new JSONArray();
				for (TdPProjectParam item : list) {
					JSONObject childrenJsonObject = new JSONObject();
					childrenJsonObject.put("id", item.getParamCode());
					childrenJsonObject.put("title", item.getParamName() + "( " + item.getParamCode() + " )");
					jsonArray.add(childrenJsonObject);
				}
				jsonObject.put("children", jsonArray);
			}
		} else {
			jsonObject.put("id", "reqHead");
			jsonObject.put("title", "请求头");
		}

		return jsonObject;
	}

	public JSONArray getInputParamTree(JSONArray jsonArray, List<VInterfaceParam> list,
			Integer interfaceId,
			String direction) {
		for (VInterfaceParam item : list) {
			if (item.getParamType().equals(ParamTypeConstants.COMMON)) {// 普通
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("id", item.getParamCode());
				jsonObject.put("title", item.getParamName() + "( " + item.getParamCode() + " )");
				jsonArray.add(jsonObject);
			} else if (item.getParamType().equals(ParamTypeConstants.LIST)
					|| item.getParamType().equals(ParamTypeConstants.OBJECT)) {// 对象或者对象
				JSONObject object = new JSONObject();
				object.put("id", item.getParamCode());
				object.put("title", item.getParamName() + "( " + item.getParamCode() + " )");
				jsonArray.add(object);
				VInterfaceParamExample example = new VInterfaceParamExample();
				example.or().andInterfaceIdEqualTo(interfaceId).andParentParamIdEqualTo(item.getParamId())
						.andParamDirectionEqualTo(direction);
				List<VInterfaceParam> list2 = vInterfaceParamMapper.selectByExample(example);
				JSONArray array = getInputParamTree(new JSONArray(), list2, interfaceId, direction);
				object.put("children", array);
			}
		}
		return jsonArray;
	}

	@Override
	public TdPProject selectTdPProjectByProjectId(Integer projectId) {
		// TODO Auto-generated method stub
		return tdPProjectMapper.selectByPrimaryKey(projectId);
	}

	@Override
	public void checkDir(String parentDir) throws Exception {
		// TODO Auto-generated method stub
		File parent = new File(parentDir);
		if (!parent.exists()) {
			parent.mkdirs();
		}
	}

	@Override
	public void getProjectInterfaceDocument(String projectDir, TdPProject tdPProject, PageData<VProjectIntf> data)
			throws Exception {
		// TODO Auto-generated method stub
		StringBuffer stringBuffer = new StringBuffer();
		File file = new File(projectDir + "/" + tdPProject.getProjectName() + ".html");
		if (!file.exists()) {
			file.createNewFile();
		}
		FileWriter fileWriter = new FileWriter(file.getAbsoluteFile());

		for(VProjectIntf vProjectIntf:data.getData()) {
			stringBuffer.append("<li class=\"\">");
			stringBuffer.append("<a href=\"");
			stringBuffer.append("../page/" + vProjectIntf.getInterfaceName() + ".html");
			stringBuffer.append("\" target=\"iframe_a\">");
			stringBuffer.append("<i class=\"layui-icon\" style=\"top: 3px;\"></i><cite>")
					.append(vProjectIntf.getInterfaceName())
					.append("</cite>\r\n" + "						</a>\r\n" + "					</li>");
		}
		BufferedWriter bw = new BufferedWriter(fileWriter);
		bw.write(stringBuffer.toString());
		bw.flush();
		bw.close();

	}

	@Override
	public void getInterfaceParamsDocument(String projectDir, TdPProject tdPProject, PageData<VProjectIntf> data,String type)
			throws Exception {
		// TODO Auto-generated method stub

		for (VProjectIntf vProjectIntf : data.getData()) {
			File file = new File(projectDir + "/" + vProjectIntf.getInterfaceName() + ".html");
			if (!file.exists()) {
				file.createNewFile();
			}
			FileWriter fileWriter = new FileWriter(file.getAbsoluteFile());
			BufferedWriter bw = new BufferedWriter(fileWriter);
			StringBuffer stringBuffer = new StringBuffer();
			stringBuffer.append("<html>\r\n" + "<head>\r\n" + "  <title>Evernote Export</title>\r\n"
					+ "  <basefont face=\"微软雅黑\" size=\"2\" />\r\n"
					+ "  <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\r\n"
					+ "  <meta name=\"exporter-version\" content=\"YXBJ Windows/602498 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\"/>\r\n"
					+ "  <meta name=\"content-class\" content=\"yinxiang.markdown\"/>\r\n" + "  <style>\r\n"
					+ "    body, td {\r\n" + "      font-family: 微软雅黑;\r\n" + "      font-size: 10pt;\r\n" + "    }\r\n"
					+ "  </style>\r\n" + "</head>\r\n" + "<body>");
			stringBuffer.append(
					"<div><span><div style=\"font-size: 14px; margin: 0; padding: 0; width: 100%;\"><h4 style=\"line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;\">")
					.append(vProjectIntf.getInterfaceName()).append("</h4>");
			stringBuffer.append(
					"<h5 style=\"line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;\">")
					.append(" 接口属性");
			stringBuffer.append("</h5>");
			stringBuffer.append(
					"<h5 style=\"line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;\">")
					.append(" 业务需求描述");
			stringBuffer.append("</h5>");
			stringBuffer.append(
					"<h5 style=\"line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;\">")
					.append(" 场景描述");
			stringBuffer.append("</h5>");
			stringBuffer.append(vProjectIntf.getDescription());
			stringBuffer.append(
					"<h5 style=\"line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;\">")
					.append(" 输入说明");
			stringBuffer.append("</h5>");
			stringBuffer
					.append("<h6 style=\"line-height: 160%; box-sizing: content-box; font-size: 13px; color: #333;\">")
					.append(" 入参说明");
			stringBuffer.append("</h6>");
			stringBuffer.append("<table style=\"margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;\">");
			stringBuffer.append("<thead style=\"line-height: 160%; box-sizing: content-box;\"><tr style=\"line-height: 160%; box-sizing: content-box;\">");
			stringBuffer.append("<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">编号</th>\r\n" + 
					"<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">参数编码</th>\r\n" + 
					"<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">参数名称</th>\r\n" + 
					"<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">参数类型</th>\r\n" + 
					"<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">描述</th>\r\n" + 
					"<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">父参编号</th>\r\n" + 
					"<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">数据类型</th>\r\n" + 
							"<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">是否非空</th>");
			stringBuffer.append("</tr>\r\n" + "</thead>");
			stringBuffer.append("<tbody style=\"line-height: 160%; box-sizing: content-box;\">");
			stringBuffer = getInputAndOutputHtml(stringBuffer, ParamDirectionConstants.INPUT,
					vProjectIntf.getInterfaceId(),type);
			stringBuffer.append("</tbody>");
			stringBuffer.append("</table>");
			stringBuffer
					.append("<h6 style=\"line-height: 160%; box-sizing: content-box; font-size: 13px; color: #333;\">")
					.append(" 样例报文");
			stringBuffer.append(
					"<pre style=\"line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;\">\r\n"
							+ "<code style=\"display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;\">\r\n"
							+ "</code></pre>");
			stringBuffer.append(
					"<h5 style=\"line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;\">")
					.append(" 输出说明");
			stringBuffer.append("</h5>");
			stringBuffer
					.append("<h6 style=\"line-height: 160%; box-sizing: content-box; font-size: 13px; color: #333;\">")
					.append(" 出参说明");
			stringBuffer.append("</h6>");
			stringBuffer.append(
					"<table style=\"margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;\">");
			stringBuffer.append(
					"<thead style=\"line-height: 160%; box-sizing: content-box;\"><tr style=\"line-height: 160%; box-sizing: content-box;\">\r\n"
							+ "<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">编号</th>\r\n"
							+ "<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">参数编码</th>\r\n"
							+ "<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">参数名称</th>\r\n"
							+ "<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">参数类型</th>\r\n"
							+ "<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">描述</th>\r\n"
							+ "<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">父参编号</th>\r\n"
							+ "<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">数据类型</th>\r\n"
							+ "<th style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;\">是否非空</th>\r\n"
							+ "</tr></thead>");
			stringBuffer.append("</tr>\r\n" + "</thead>");
			stringBuffer.append("<tbody style=\"line-height: 160%; box-sizing: content-box;\">");
			stringBuffer = getInputAndOutputHtml(stringBuffer, ParamDirectionConstants.OUTPUT,
					vProjectIntf.getInterfaceId(),type);
			stringBuffer.append("</tbody>");
			stringBuffer.append("</table>");
			bw.write(stringBuffer.toString());
			bw.flush();
			bw.close();
		}


	}

	public StringBuffer getInputAndOutputString(StringBuffer stringBuffer, String paramDirection, Integer interfaceId) {
		VInterfaceParamExample example = new VInterfaceParamExample();
		if(paramDirection.equals(ParamDirectionConstants.INPUT)) {
			example.or().andInterfaceIdEqualTo(interfaceId)
			.andParamDirectionEqualTo(ParamDirectionConstants.INPUT)
			.andIsDeletedEqualTo(IsDeletedConstants.IN_USE);
		}else {
			example.or().andInterfaceIdEqualTo(interfaceId)
			.andParamDirectionEqualTo(ParamDirectionConstants.OUTPUT)
			.andIsDeletedEqualTo(IsDeletedConstants.IN_USE);
		}
		example.setOrderByClause("param_direction , param_id , parent_param_id");
		PageData<VInterfaceParam> inputData = this.getPageData(example);
		for (VInterfaceParam vInterfaceParam : inputData.getData()) {
			stringBuffer.append(vInterfaceParam.getParamId()).append("|").append(vInterfaceParam.getParamCode())
					.append("|").append(vInterfaceParam.getParamName()).append("|");
			if (vInterfaceParam.getParamType().equals(ParamTypeConstants.COMMON)) {
				stringBuffer.append("普通");
			} else if (vInterfaceParam.getParamType().equals(ParamTypeConstants.LIST)) {
				stringBuffer.append("列表");
			} else if (vInterfaceParam.getParamType().equals(ParamTypeConstants.OBJECT)) {
				stringBuffer.append("对象");
			}else  {
				stringBuffer.append(" ");
			}
			stringBuffer.append("|").append(vInterfaceParam.getDescription()).append("|")
					.append(vInterfaceParam.getParentParamId() != null ? vInterfaceParam.getParentParamId() : "")
					.append("|");
			if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_BIG_DECIMAL)) {
				stringBuffer.append("BigDecimal");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_INTEGER)) {
				stringBuffer.append("Integer");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_LONG)) {
				stringBuffer.append("Long");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_STRING)) {
				stringBuffer.append("String");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.NO_PARAM_DATA_TYPE)) {
				stringBuffer.append("无");
			}
			stringBuffer.append("|");
			if (vInterfaceParam.getIsNotNull().equals("1")) {
				stringBuffer.append("是");
			} else if (vInterfaceParam.getIsNotNull().equals("0")) {
				stringBuffer.append("否");
			}
			stringBuffer.append("\n");
		}
		return stringBuffer;
	}


	public StringBuffer getInputAndOutputHtml(StringBuffer stringBuffer, String paramDirection, Integer interfaceId,String type) {
		VInterfaceParamExample example = new VInterfaceParamExample();
		if (paramDirection.equals(ParamDirectionConstants.INPUT)) {
			example.or().andInterfaceIdEqualTo(interfaceId).andParamDirectionEqualTo(ParamDirectionConstants.INPUT)
					.andIsDeletedEqualTo(IsDeletedConstants.IN_USE).andParentParamIdIsNull();
		} else {
			example.or().andInterfaceIdEqualTo(interfaceId).andParamDirectionEqualTo(ParamDirectionConstants.OUTPUT)
					.andIsDeletedEqualTo(IsDeletedConstants.IN_USE).andParentParamIdIsNull();
		}
		example.setOrderByClause("param_direction , param_id, parent_param_id");

		PageData<VInterfaceParam> inputData = this.getPageData(example);
		for (VInterfaceParam vInterfaceParam : inputData.getData()) {
			stringBuffer.append("<tr style=\"line-height: 160%; box-sizing: content-box;\">");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			stringBuffer.append(vInterfaceParam.getParamId());
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");

			if("0".equals(type)){
				stringBuffer.append(vInterfaceParam.getParamCode());
			}else{
				stringBuffer.append(StringUtil.humpToLine(vInterfaceParam.getParamCode()).toUpperCase());
			}
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			stringBuffer.append(vInterfaceParam.getParamName());
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			if (vInterfaceParam.getParamType().equals(ParamTypeConstants.COMMON)) {
				stringBuffer.append("普通");
			} else if (vInterfaceParam.getParamType().equals(ParamTypeConstants.LIST)) {
				stringBuffer.append("列表");
			} else if (vInterfaceParam.getParamType().equals(ParamTypeConstants.OBJECT)) {
				stringBuffer.append("对象");
			} else {
				stringBuffer.append(" ");
			}
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			stringBuffer.append(vInterfaceParam.getDescription());
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			stringBuffer.append(vInterfaceParam.getParentParamId() != null ? vInterfaceParam.getParentParamId() : "");
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_BIG_DECIMAL)) {
				stringBuffer.append("BigDecimal");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_INTEGER)) {
				stringBuffer.append("Integer");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_LONG)) {
				stringBuffer.append("Long");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_STRING)) {
				stringBuffer.append("String");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.NO_PARAM_DATA_TYPE)) {
				stringBuffer.append("无");
			}
			stringBuffer.append("</td>");

			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");

			if (vInterfaceParam.getIsNotNull().equals("1")) {
				stringBuffer.append("是");
			} else if (vInterfaceParam.getIsNotNull().equals("0")) {
				stringBuffer.append("否");
			}
			stringBuffer.append("</td>");
			stringBuffer.append("</tr>");
			getInputAndOutputHtmlChild(stringBuffer, paramDirection, vInterfaceParam.getParamId(), interfaceId,type);
		}
		return stringBuffer;
	}

	public StringBuffer getInputAndOutputHtmlChild(StringBuffer stringBuffer, String paramDirection,
			Integer parentParamId, Integer interfaceId,String type) {
		VInterfaceParamExample example = new VInterfaceParamExample();
		if (paramDirection.equals(ParamDirectionConstants.INPUT)) {
			example.or().andInterfaceIdEqualTo(interfaceId).andParentParamIdEqualTo(parentParamId)
					.andParamDirectionEqualTo(ParamDirectionConstants.INPUT)
					.andIsDeletedEqualTo(IsDeletedConstants.IN_USE);
		} else {
			example.or().andInterfaceIdEqualTo(interfaceId).andParentParamIdEqualTo(parentParamId)
					.andParamDirectionEqualTo(ParamDirectionConstants.OUTPUT)
					.andIsDeletedEqualTo(IsDeletedConstants.IN_USE);
		}
		example.setOrderByClause("param_direction , param_id, parent_param_id");

		PageData<VInterfaceParam> inputData = this.getPageData(example);
		for (VInterfaceParam vInterfaceParam : inputData.getData()) {
			stringBuffer.append("<tr style=\"line-height: 160%; box-sizing: content-box;\">");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			stringBuffer.append(vInterfaceParam.getParamId());
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			if("0".equals(type)){
				stringBuffer.append(vInterfaceParam.getParamCode());
			}else{
				stringBuffer.append(StringUtil.humpToLine(vInterfaceParam.getParamCode()).toUpperCase());
			}
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			stringBuffer.append(vInterfaceParam.getParamName());
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			if (vInterfaceParam.getParamType().equals(ParamTypeConstants.COMMON)) {
				stringBuffer.append("普通");
			} else if (vInterfaceParam.getParamType().equals(ParamTypeConstants.LIST)) {
				stringBuffer.append("列表");
			} else if (vInterfaceParam.getParamType().equals(ParamTypeConstants.OBJECT)) {
				stringBuffer.append("对象");
			} else {
				stringBuffer.append(" ");
			}
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			stringBuffer.append(vInterfaceParam.getDescription());
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			stringBuffer.append(vInterfaceParam.getParentParamId() != null ? vInterfaceParam.getParentParamId() : "");
			stringBuffer.append("</td>");
			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");
			if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_BIG_DECIMAL)) {
				stringBuffer.append("BigDecimal");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_INTEGER)) {
				stringBuffer.append("Integer");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_LONG)) {
				stringBuffer.append("Long");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.IS_STRING)) {
				stringBuffer.append("String");
			} else if (vInterfaceParam.getParamDataType().equals(ParamDataTypeConstants.NO_PARAM_DATA_TYPE)) {
				stringBuffer.append("无");
			}
			stringBuffer.append("</td>");

			stringBuffer.append(
					"<td style=\"line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;\">");

			if (vInterfaceParam.getIsNotNull().equals("1")) {
				stringBuffer.append("是");
			} else if (vInterfaceParam.getIsNotNull().equals("0")) {
				stringBuffer.append("否");
			}
			stringBuffer.append("</td>");
			stringBuffer.append("</tr>");
			getInputAndOutputHtmlChild(stringBuffer, paramDirection, vInterfaceParam.getParamId(), interfaceId, type);
		}

		return stringBuffer;
	}

}
